#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

int main() {
    std::vector<int> serj;
    for (int i = 2; i < 1000; i++) {
        int f = 1;
        for (int j = 2; j <= i / 2; j++) {
            if (i % j == 0) {
                f = 0;
                break;
            }
        }
        if (f) {
            serj.push_back(i);
        }
    }

    std::vector<std::string> num = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::string ch;
    std::getline(std::cin, ch);
    ch = std::regex_replace(ch, std::regex("[0-9]"), "&");
    if (std::count(ch.begin(), ch.end(), ' ') != 2 || ch.find("&") != std::string::npos) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::vector<std::string> d = {"", "", ""};
        int i = 0;
        std::string word = "";
        for (char c : ch) {
            if (c == ' ') {
                d[i++] = word;
                word = "";
            } else {
                word += c;
            }
        }
        d[i] = word;

        std::string new_str = "";
        for (const std::string& s : d) {
            new_str += std::to_string(std::find(num.begin(), num.end(), s) - num.begin());
        }
        int grate_maks = std::stoi(new_str);

        std::vector<std::pair<int, int>> razn;
        for (int i : serj) {
            razn.emplace_back(std::abs(grate_maks - i), i);
        }
        std::sort(razn.begin(), razn.end());
        std::cout << razn[0].second << std::endl;
    }
    return 0;
}

